// __PUBLIC__/js/page/admin/content/addtopic
require(['../../common'], function() {
  require(['content.addtopic'])
})

define('content.addtopic', [
  'jquery',
  'jqp/validate',
  'css!ke/themes/default/default.css',
  'ke/kindeditor'
], function($) {
  'use strict';

  $('#J_form').validate({
    classPlace: '.kv',
    errorPlace: '.kv-error',
    errors: {
      name: {
        required: '请填写话题名称',
      },
    }
  })

  // $(document).ready(function() {
    var langType = document.documentElement.lang || 'zh-CN'
    var langMap = {
      'zh-CN': 'zh_CN',
      'zh-TW': 'zh_TW',
      'en-US': 'en'
    }
    var editor = KindEditor.editor({
      allowFileManager : true,
      langType: langMap[langType],
      uploadJson:APP + '?app=cms&m=Cate&a=uploadPic',
      fileManagerJson:APP + '?app=cms&m=Cate&a=getServerPic',
    })

    // 只有 KindEditor.create() 才加载指定语言， 其它方法手动加载
    KindEditor.loadScript(editor.langPath + editor.langType + '.js?ver=' + encodeURIComponent(KindEditor.VERSION))

    KindEditor('#image').click(function() {
      editor.loadPlugin('image', function() {
        editor.plugin.imageDialog({
          hiddenSizeAlignTitle : false,
          imageUrl : KindEditor('#imageurl').val(),
          clickFn : function(url, title, width, height, border, align) {
            KindEditor('#imageurl').val(url)
            $('#show_pic').attr('src',url)
            editor.hideDialog()
          }
        })
      })
    })
  // })

  /*M.addEventFns({
      search_user: {
          load: function() {
              var obj = $(this);
              if ('undefined' == typeof(core.searchUser)) {
                  core.plugFunc('searchUser',
                  function() {
                      core.searchUser.init(obj, '0', '0', '', '0');
                      core.searchUser._stopUser();
                  });
              }
          },
          click: function() {
              var args = M.getEventArgs(this);
              if (this.value == args.defaultValue) {
                  this.value = ''
              };
              var obj = $(this);
              core.searchUser.init(obj, '0', '0', '', '0');
          },
          blur: function() {
              var args = M.getEventArgs(this);
              if (this.value == '' || this.value == args.defaultValue) {
                  this.value = args.defaultValue;
                  core.searchUser.inputReset();
              }
          },
          focus: function() {
              var args = M.getEventArgs(this);
              if (this.value == args.defaultValue) {
                  this.value = '';
              }
              core.searchUser.init($(this), '0', '0', '', '0');
          }
      }
  });*/

})
